<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>寻找重复数</title>
</head>
<body>
  <script>
    function fn(nums) {
      /// 双指针
      let slow = 0
      let fast = 1
      nums = nums.sort((a, b) => a - b)
      while (slow < fast) {
        if (nums[slow] === nums[fast]) {
          return nums[slow]
        }
        slow++
        fast++
      }
    };
    console.log(fn([1, 3, 4, 2, 2]))
  </script>
</body>
</html>